import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { SkillPropItem } from "./SkillPropItem";
import { ItemData } from "../../../resource/info/ItemData";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
type int = number;
//class SkillPropRenderer
    
    export  class SkillPropRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            ObjCreate.createBitmap(ImagesConst.PackItemBg, 0, 0, this);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(33, 33);
            this._baseItem.move(2, 2);
            addChild(this._baseItem);
            addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=0;
            super.data = arg1;
            if (arg1 && arg1 is SkillPropItem) 
            {
                loc1 = arg1 as SkillPropItem;
                this._playerItem = loc1.playerItem;
                if (this._playerItem) 
                {
                    this._baseItem.itemData = new ItemData(this._playerItem);
                    this._baseItem.amount = 0;
                }
                else 
                {
                    this._baseItem.itemData = null;
                }
                if (loc1.isUse) 
                {
                    this._baseItem.filters = [FilterConst.colorFilter];
                    this.mouseChildren = false;
                    this.mouseEnabled = false;
                    this.useHandCursor = false;
                }
                else 
                {
                    this._baseItem.filters = [];
                    mouseChildren = true;
                    this.mouseEnabled = true;
                    this.useHandCursor = true;
                }
            }
            else if (arg1 && arg1 is int) 
            {
                this._playerItem = null;
                loc2 = arg1 as int;
                if (loc2 != 0) 
                {
                    this._baseItem.itemData = new ItemData(loc2);
                }
            }
            else 
            {
                this._playerItem = null;
                this._baseItem.itemData = null;
            }
            draw();
            return;
        }

        /* internal  */onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._playerItem) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.UpgradeCrossSecretPropSelect, this._playerItem));
            }
            return;
        }

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_playerItem: SPlayerItem;
    }
